<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>时间记录器</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            text-align: center;
            background-color: #f4f4f9;
            color: #333;
        }
        h1 {
            color: #007bff;
        }
        button {
            padding: 10px 20px;
            font-size: 16px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            margin-bottom: 20px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        }
        button:hover {
            background-color: #0056b3;
        }
        .log-container {
            display: flex;
            flex-direction: column;
            gap: 10px;
            align-items: center;
        }
        .log-entry {
            background-color: #ffffff;
            padding: 15px;
            width: 90%;
            max-width: 400px;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            text-align: left;
        }
        .log-entry .time {
            font-size: 16px;
            font-weight: bold;
            color: #333;
        }
        .log-entry .diff {
            font-size: 14px;
            color: #ff5722;
            margin-top: 5px;
        }
    </style>
</head>
<body>
    <h1>时间记录器</h1>
    <button onclick="recordTime()">记录当前时间</button>
    <div class="log-container" id="log"></div>

    <script>
        let lastTimestamp = null;

        function formatTimeDifference(seconds) {
            if (seconds < 60) {
                return `${seconds} 秒`;
            }
            const minutes = Math.floor(seconds / 60);
            const remainingSeconds = seconds % 60;
            return `${minutes} 分 ${remainingSeconds} 秒`;
        }

        function recordTime() {
            const logDiv = document.getElementById('log');
            const now = new Date();
            const currentTimestamp = now.getTime();
            const beijingTime = now.toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai' });

            let timeDifferenceHTML = '';
            if (lastTimestamp !== null) {
                const diffSeconds = Math.floor((currentTimestamp - lastTimestamp) / 1000);
                timeDifferenceHTML = `<div class="diff">距离上次记录过去了 ${formatTimeDifference(diffSeconds)}</div>`;
            }

            const logEntryHTML = `
                <div class="log-entry">
                    <div class="time">记录时间: ${beijingTime}</div>
                    ${timeDifferenceHTML}
                </div>
            `;
            logDiv.innerHTML = logEntryHTML + logDiv.innerHTML; // 新记录在最上方显示

            // 更新上次时间戳
            lastTimestamp = currentTimestamp;
        }
    </script>
</body>
</html>
